package com.nuoniu.sibanyun.controller.erp;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.nuoniu.sibanyun.common.BaseController;
import com.nuoniu.sibanyun.common.exception.NuoNiuException;
import com.nuoniu.sibanyun.common.result.HttpResult;
import com.nuoniu.sibanyun.entity.erp.ErpAccountRuleSet;
import com.nuoniu.sibanyun.service.erp.IErpAccountRuleSetService;
import com.nuoniu.sibanyun.service.erp.IErpAccountService;
import com.nuoniu.sibanyun.userThread.UserThreadLocal;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 账套-选项设置
 * @author 小啊刚
 * @date 2020-11-07
 */
@RestController
@RequestMapping("/erp/accountRuleSet")
@Api(value="账套-选项设置 ",tags={"账套-选项设置"})
public class ErpAccountRuleSetController extends BaseController {

    @Autowired
    private IErpAccountRuleSetService ruleSetService;

    @Autowired
    private IErpAccountService erpAccountService;

    /**
     * 获取选项设置列表
     * @author 小啊刚
     * @date 2020-11-07
     */
    @GetMapping("list")
    @ApiOperation("获取选项设置列表 ")
    @ApiImplicitParam(value = "模块名称", name = "moduleCode")
    public HttpResult<ErpAccountRuleSet> list(String moduleCode) {
        Integer currentAccountId = erpAccountService.getCurrentAccountId();
        if(null == currentAccountId)throw new NuoNiuException("当前账套已经结算或者没有账套");
        ErpAccountRuleSet set = new ErpAccountRuleSet();
        set.setSysModuleCode(moduleCode);
        set.setAccountId(currentAccountId);
        set.setCompanyId(UserThreadLocal.get().getCompanyId());
        QueryWrapper<ErpAccountRuleSet> wrapper = new QueryWrapper(set);
        return HttpResult.ok(ruleSetService.list(wrapper));
    }

    @PostMapping("save")
    @ApiOperation("保存选项设置")
    public HttpResult save(@RequestBody List<ErpAccountRuleSet> erpAccountRuleSetList) {
        ruleSetService.updateBatchById(erpAccountRuleSetList);
        return HttpResult.ok();
    }


}
